/// <reference path="../typings/index.d.ts" />
/// <reference path="../src/receivableService.ts" />
/// <reference path="../src/tms.ts" />

//获取应收总额
describe('getTotalReceivable', () => {
    var injector: ng.auto.IInjectorService;
    var service: IReceivableService;

    beforeEach(() => {
        injector = angular.injector(['ng', 'tms']);
        service = injector.get<IReceivableService>('receivableService');
    });

    it('test getTotalReceivable by all exits params', (done) => {
        service.getTotalReceivable('客户单位', '小布娃娃', '结算单位编号', '商务专员编号', '2016.08.02 09:59', '2016.09.02 09:59', '苏Z11111', '合同短号', '有回单', '办理', '江苏镇江', '湖北恩施', '应收总单编号', true, '应收编号1', '短驳费', true, '应收结算总单可识别编号', '已发货', '牛奶').then((res) => {
            expect(res.data.totalReceivable).toBe(10000);
            done();
        }, (err) => {
            done.fail(err);
        })
    })
})


//获取应收列表
describe('receivablelist', () => {
    var injector: ng.auto.IInjectorService;
    var service: IReceivableService;

    beforeEach(() => {
        injector = angular.injector(['ng', 'tms']);
        service = injector.get<IReceivableService>('receivableService');
    });


    it('test receivablelist by normal', (done) => {
        service.receivablelist('枚举1', true, '客户单位', '小布娃娃', '结算单位编号', '商务专员编号', '2016.08.02 09:59', '2016.09.02 09:59', '苏Z11111', '合同短号', '有回单', '办理', '', '', '', true, '', '短驳费', true, '', '已发货', '', 0, 10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('枚举1|true|客户单位|小布娃娃|结算单位编号|商务专员编号|2016.08.02 09:59|2016.09.02 09:59|苏Z11111|合同短号|有回单|办理||||true||短驳费|true||已发货||0|10');
            done();
        }, (err) => {
            done.fail(err);
        })
    })

    it('test receivablelist by all exits params', (done) => {
        service.receivablelist(null, true, null, null, null, null, null, null, null, null, null, null, null, null, null, true, null, null, true, null, null, null, 0, 10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|true||||||||||||||true|||true||||0|10');
            done();
        }, (err) => {
            done.fail(err);
        })
    })

    //获取回单状态'有回单'且结算状态'办理'且应收费用类型'短驳费'且订单状态'已发货'
    it('test receivablelist by receiptstatus\'有回单\'and settlestatuslist\'办理\'and feeType\'短驳费\'and orderStatus\'已发货\'', (done) => {
        service.receivablelist(null, true, null, null, null, null, null, null, null, null, '有回单', '办理', null, null, null, true, null, '短驳费', true, null, '已发货', null, 0, 10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|true|||||||||有回单|办理||||true||短驳费|true||已发货||0|10');
            done();
        }, (err) => {
            done.fail(err);
        })
    })
})


//应收审核通过
describe('audited', () => {
    var injector: ng.auto.IInjectorService;
    var service: IReceivableService;

    beforeEach(() => {
        injector = angular.injector(['ng', 'tms']);
        service = injector.get<IReceivableService>('receivableService');
    });

    //
    it('test audited by 1,2 ', (done) => {
        service.audited('应收编号1,应收编号3').then((res) => {
            expect(res.data.extData).toBe('应收编号1,应收编号3');
            done();
        }, (err) => {
            done.fail(err);
        })
    })

})

//应收撤销审核
describe('returnaudited', () => {
    var injector: ng.auto.IInjectorService;
    var service: IReceivableService;

    beforeEach(() => {
        injector = angular.injector(['ng', 'tms']);
        service = injector.get<IReceivableService>('receivableService');
    });

    it('test returnaudited by 1', (done) => {
        service.returnaudited('1').then((res) => {
            expect(res.data.extData).toBe('1');
            done();
        }, (err) => {
            done.fail(err);
        })
    })

})

//应收撤出账单
describe('withdrawnbill', () => {
    var injector: ng.auto.IInjectorService;
    var service: IReceivableService;
    beforeEach(() => {
        injector = angular.injector(['ng', 'tms']);
        service = injector.get<IReceivableService>('receivableService');
    });
    it('test withdrawnbill by 1', (done) => {
        service.withdrawnbill('1').then((res) => {
            expect(res.data.extData).toBe('1');
            done();
        }, (err) => {
            done.fail(err);
        })
    })
})


//应收退回办理
describe('returnReceivable', () => {
    var injector: ng.auto.IInjectorService;
    var service: IReceivableService;

    beforeEach(() => {
        injector = angular.injector(['ng', 'tms']);
        service = injector.get<IReceivableService>('receivableService');
    });

    it('test returnReceivable by 1', (done) => {
        service.returnReceivable('1').then((res) => {
            expect(res.data.extData).toBe('1');
            done();
        }, (err) => {
            done.fail(err);
        })
    })
})


//根据Id集合获取应收总额之和
describe('sumreceivable', () => {
    var injector: ng.auto.IInjectorService;
    var service: IReceivableService;

    beforeEach(() => {
        injector = angular.injector(['ng', 'tms']);
        service = injector.get<IReceivableService>('receivableService');
    });

    it('test sumreceivable by 1', (done) => {
        service.sumreceivable('1').then((res) => {
            expect(res.data.totalReceivable).toBe(10000);
            done();
        }, (err) => {
            done.fail(err);
        })
    })
})


//添加账单
describe('addparent', () => {
    var injector: ng.auto.IInjectorService;
    var service: IReceivableService;

    beforeEach(() => {
        injector = angular.injector(['ng', 'tms']);
        service = injector.get<IReceivableService>('receivableService');
    });


    it('test addparent by  all exit params', (done) => {
        service.addparent(10000, '应收说明', '结算单位编号', '结算单位', '客户单位', '客户单位编号', '2016.09.02 11.21', '不含税').then((res) => {
            expect(res.data.extData).toBe('10000|应收说明|结算单位编号|结算单位|客户单位|客户单位编号|2016.09.02 11.21|不含税');
            done();
        }, (err) => {
            done.fail(err);
        })
    })
})


//获取应收结算总单详情
describe('getReceivableSettleBillDetail', () => {
    var injector: ng.auto.IInjectorService;
    var service: IReceivableService;

    beforeEach(() => {
        injector = angular.injector(['ng', 'tms']);
        service = injector.get<IReceivableService>('receivableService');
    });


    it('test getReceivableSettleBillDetail by 1 ', (done) => {
        service.getReceivableSettleBillDetail('1').then((res) => {
            expect(res.data.billCode).toBe('12345');
            expect(res.data.totalMoney).toBe(10000);
            expect(res.data.description).toBe('应收说明');
            expect(res.data.invoiceStatus).toBe('未开票');
            expect(res.data.invoiceTime).toBe('2016.02.06');
            expect(res.data.settle).toBe('布娃娃');
            expect(res.data.reckoner).toBe('小牛');
            expect(res.data.creationTime).toBe('2018.06.08');
            done();
        }, (err) => {
            done.fail(err);
        })
    })
})

//应收账单对账
describe('checked', () => {
    var injector: ng.auto.IInjectorService;
    var service: IReceivableService;

    beforeEach(() => {
        injector = angular.injector(['ng', 'tms']);
        service = injector.get<IReceivableService>('receivableService');
    });


    it('test checked by all exits params', (done) => {
        service.checked('1', '已开票', '2016.09.02 11.21').then((res) => {
            expect(res.data.extData).toBe('1|已开票|2016.09.02 11.21');
            done();
        }, (err) => {
            done.fail(err);
        })
    })
})

//编辑应收价格信息
describe('edit', () => {
    var injector: ng.auto.IInjectorService;
    var service: IReceivableService;

    beforeEach(() => {
        injector = angular.injector(['ng', 'tms']);
        service = injector.get<IReceivableService>('receivableService');
    });


    it('test edit by all exits params', (done) => {
        service.edit('1', 20, '元/件', 200, 10, '吨', '应收说明').then((res) => {
            expect(res.data.extData).toBe('1|20|元/件|200|10|吨|应收说明');
            done();
        }, (err) => {
            done.fail(err);
        })
    })
})


//添加应收到总单
describe('toparent', () => {
    var injector: ng.auto.IInjectorService;
    var service: IReceivableService;

    beforeEach(() => {
        injector = angular.injector(['ng', 'tms']);
        service = injector.get<IReceivableService>('receivableService');
    });


    it('test toparent by all exits params', (done) => {
        service.toparent('11', '222', 'description').then((res) => {
            expect(res.data.extData).toBe('11|222|description');
            done();
        }, (err) => {
            done.fail(err);
        })
    })
})

//添加收入
describe('income', () => {
    var injector: ng.auto.IInjectorService;
    var service: IReceivableService;

    beforeEach(() => {
        injector = angular.injector(['ng', 'tms']);
        service = injector.get<IReceivableService>('receivableService');
    });
    it('test income by all exits params', (done) => {
        service.income(5000, '说明字段', '结算单位编号', '小布娃娃', '2016.09.09 14.00').then((res) => {
            expect(res.data.extData).toBe('5000|说明字段|结算单位编号|小布娃娃|2016.09.09 14.00')
            done();
        }, (err) => {
            done.fail(err);
        })
    })
})


//删除收入
describe('deleteincome', () => {
    var injector: ng.auto.IInjectorService;
    var service: IReceivableService;

    beforeEach(() => {
        injector = angular.injector(['ng', 'tms']);
        service = injector.get<IReceivableService>('receivableService');
    });


    it('test deleteincome by 61609020010', (done) => {
        service.deleteincome('61609020010').then((res) => {
            expect(res.data.extData).toBe('61609020010');
            done();
        }, (err) => {
            done.fail(err);
        })
    })
})

//获取收入列表
describe('incomeList', () => {
    var injector: ng.auto.IInjectorService;
    var service: IReceivableService;

    beforeEach(() => {
        injector = angular.injector(['ng', 'tms']);
        service = injector.get<IReceivableService>('receivableService');
    });


    it('get incomeList by all exits params', (done) => {
        service.incomeList('小布娃娃', '2016-09-10 11:00:00', '2016-09-15 11:00:00').then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('小布娃娃|2016-09-10 11:00:00|2016-09-15 11:00:00');
            done();
        }, (err) => {
            done.fail(err);
        })
    })
})



//获取应收统计详情
describe('statistics', () => {
    var injector: ng.auto.IInjectorService;
    var service: IReceivableService;

    beforeEach(() => {
        injector = angular.injector(['ng', 'tms']);
        service = injector.get<IReceivableService>('receivableService');
    });


    it('get  statistics by all exits params', (done) => {
        service.statistics('小布娃娃', '2016-09-10 11:00:00', '2016-09-15 11:00:00').then((res) => {
            expect(res.data.alreadyInvoiceAmount).toBe(10000);
            expect(res.data.excludingTaxAmount).toBe(8000);
            expect(res.data.incomeAmount).toBe(5000);
            expect(res.data.uncollectedAmount).toBe(10000);
            expect(res.data.accountEnRouteAmount).toBe(5000);
            expect(res.data.allBalance).toBe(10000);
            expect(res.data.settle).toBe('元/吨');
            done();
        }, (err) => {
            done.fail(err);
        })
    })

})

//获取应收统计列表
describe('statisticslist', () => {
    var injector: ng.auto.IInjectorService;
    var service: IReceivableService;

    beforeEach(() => {
        injector = angular.injector(['ng', 'tms']);
        service = injector.get<IReceivableService>('receivableService');
    });

    it('text statisticslist by normal params ', (done) => {
        service.statisticslist(null, null, null, 0, 10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|||0|10');
            done();
        }, (err) => {
            done.fail(err);
        })
    })


    it('text statisticslist by all exits params', (done) => {
        service.statisticslist('小布娃娃', '2016-09-10 11:00:00', '2016-09-15 11:00:00', 0, 10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('小布娃娃|2016-09-10 11:00:00|2016-09-15 11:00:00|0|10');
            done();
        }, (err) => {
            done.fail(err);
        })
    })

})


//新增应收
describe('addnewreceivable', () => {
    var injector: ng.auto.IInjectorService;
    var service: IReceivableService;

    beforeEach(() => {
        injector = angular.injector(['ng', 'tms']);
        service = injector.get<IReceivableService>('receivableService');
    });


    it('test addnewreceivable by all exits params ', (done) => {
        service.addnewreceivable('客户id', '发货地省编号', '发货地市编号', '发货地区编号', '发货地详细地址', '送货地省编号', '送货地市编号', '送货地区编号', '送货地详细地址', '货物编号', '货物类型编号', 1000, '货物数量单位', 1000, '元/件', 1000, '元/件', 5000, '应收说明', '承运商编号', '车辆编号', '合同编号', '驾驶证号', '开户银行', '银行卡号', '持卡人', '发货时间', '到货时间', '结算账单编号', '客户单位短号').then((res) => {
            expect(res.data.extData).toBe('客户id|发货地省编号|发货地市编号|发货地区编号|发货地详细地址|送货地省编号|送货地市编号|送货地区编号|送货地详细地址|货物编号|货物类型编号|1000|货物数量单位|1000|元/件|1000|元/件|5000|应收说明|承运商编号|车辆编号|合同编号|驾驶证号|开户银行|银行卡号|持卡人|发货时间|到货时间|结算账单编号|客户单位短号');
            done();
        }, (err) => {
            done.fail(err);
        })
    })

})


//添加应收结算总单
describe('addReceivableSettleBill', () => {
    var injector: ng.auto.IInjectorService;
    var service: IReceivableService;

    beforeEach(() => {
        injector = angular.injector(['ng', 'tms']);
        service = injector.get<IReceivableService>('receivableService');
    });

    it('test addReceivableSettleBill by all exits params', (done) => {
        service.addReceivableSettleBill('应收说明', ['应收子单编号1', '应收子单编号2']).then((res) => {
            expect(res.data.extData).toBe('应收说明|2');
            done();
        }, (err) => {
            done.fail(err);
        })
    })

})



//获取应收结算总单列表
describe('getReceivableSettleBillList', () => {
    var injector: ng.auto.IInjectorService;
    var service: IReceivableService;

    beforeEach(() => {
        injector = angular.injector(['ng', 'tms']);
        service = injector.get<IReceivableService>('receivableService');
    });

    it('text statisticslist by normal params ', (done) => {
        service.getreceivableSettleBillList(null, true, null, null, null, null, null, null, null, null, null, null, 0, 10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|true|||||||||||0|10');
            done();
        }, (err) => {
            done.fail(err);
        })
    })

    it('text statisticslist by all exits params ', (done) => {
        service.getreceivableSettleBillList('12', true, '34', '56', '78', '123', '456', '789', '1234', '5678', '111', '小布娃娃', 0, 10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('12|true|34|56|78|123|456|789|1234|5678|111|小布娃娃|0|10');
            done();
        }, (err) => {
            done.fail(err);
        })
    })

    //获取开票状态包含'已开票'且客户单位包含'小布娃娃'应收结算总单列表
    it('text statisticslist by status \'已开票\'and client \'小布娃娃\'', (done) => {
        service.getreceivableSettleBillList(null, true, null, null, null, null, null, null, null, null, '已开票', '小布娃娃', 0, 10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|true|||||||||已开票|小布娃娃|0|10');
            done();
        }, (err) => {
            done.fail(err);
        })
    })
})